public class Array01 {

    public static void main(String[] args) {
        /*
        它们的体重分别为3kg,5kg,1kg,3.4kg,2kg,50kg
        请问这六只鸡的总体重是多少？平均体重是多少？
        */
        //1.传统方法
        double hen1 = 3;
        double hen2 = 5;
        double hen3 = 1;
        double hen4 = 3.4;
        double hen5 = 2;
        double hen6 = 50;
        double totalWeight = hen1 + hen2 + hen3 + hen4 + hen5 + hen6;
        double avgWeight = totalWeight / 6;
        System.out.println("总体重是"+totalWeight);
        System.out.println("平均体重是"+avgWeight);
        //2.数组
        double[] hens = {3,5,1,3.4,2,50};
        System.out.println("===使用数组解决===");
        for (int i = 0;i<hens.length;i++) {
            System.out.println("第"+(i+1)+"个元素的值="+hens[i]);
            totalWeight += hens[i];
        }
        System.out.println("总体重="+totalWeight+"\n"+"平均体重="+totalWeight/hens.length);
    }
}
